package net.util;

import java.util.Arrays;

public class CharSequenceUtil
{
	private CharSequenceUtil()
	{
		
	}
	
	public static final char SUPER_0 = 0x2070, 
							 SUPER_1 = 0x00B9,
							 SUPER_2 = 0x00B2,
							 SUPER_3 = 0x00B3,
							 SUPER_4 = 0x2074,
							 SUPER_5 = 0x2075,
							 SUPER_6 = 0x2076,
							 SUPER_7 = 0x2077,
							 SUPER_8 = 0x2078,
							 SUPER_9 = 0x2079,
							 SUPER_PLUS = 0x207A,
							 SUPER_MINUS = 0x207B;
	
	public static int strHeight(String str)
	{
		return 1 + str.split("\n").length;
	}

	public static int strWidth(String str)
	{
		String[] lines = str.split("\n");
		
		int m = 0;
		
		for(String line : lines)
		{
			if (line.length() > m)
			{
				m = line.length();
			}
		}
		
		return m;
	}

	public static String strInBox(int w, int h, String str)
	{
		String result = "";
		
		if (!str.contains("\n"))
		{
			str = str.concat("\n");
		}
		
		String[] lines = str.split("\n");
	
		for(int n = 0; n < lines.length; n++)
		{
			if (lines[n].length() > w)
			{
				lines[n] = lines[n].substring(0, w);
			}
		}
		
		lines = Arrays.copyOfRange(lines, 0, h);
		
		for (String line : lines)
		{
			result += line == null ? "" : (line + '\n');
		}
		
		return result;
	}
}
